package com.zxmr.domain.service;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.zxmr.CommonInit;
import com.zxmr.db.DBManager;
import com.zxmr.domain.Notification;

public class NotificationService {

	DBManager db = CommonInit.getDBManager();
	
	public void setAsReaded(Notification noti)
	{
		try {
			db.getMapper().update("notification.update", noti);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	public void add(Notification noti)
	{
		try {
			db.getMapper().insert("notification.add", noti);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	public Notification query(long id,String user)
	{
		try{
			Map<String,Object> para = new HashMap<String,Object>();
			para.put("id", id);
			para.put("user", user);
			
			return (Notification)db.getMapper().queryForObject("notification.query", para);
		}catch(SQLException e)
		{
			e.printStackTrace();
		}
		return null;
	}
	
	@SuppressWarnings("unchecked")
	public List<Notification> queryAllUnRead(String user)
	{
		try
		{
			return (List<Notification>)db.getMapper().queryForList("notification.queryUnRead", user);
		}catch(SQLException e)
		{
			e.printStackTrace();
		}
		return null;
	}
}
